package com.danbay.cloud.account.service.api;

import com.danbay.cloud.account.dto.AccountGroupDto;
import com.danbay.cloud.account.dto.AccountDto;
import com.danbay.cloud.account.dto.ChangePwd;
import com.danbay.cloud.account.dto.FindPwdDto;
import com.danbay.cloud.base.user.LoginUserInfo;
import com.danbay.framework.exception.BusinessException;
import com.danbay.framework.springnc.annotation.AutoController;
import com.danbay.framework.springnc.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author SJG
 *         2017/12/19.
 */
@AutoController
@RequestMapping("/account-service/account")
@Api("账户操作接口")
public interface IAccountService {

    /**
     * 添加账户
     * 密码为空时将使用默认密码
     *
     * @param account 账户信息
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "添加账户", notes = "密码为空时将使用默认密码")
    @RequestMapping(value = "/addAccount", method = RequestMethod.POST)
    void addAccount(AccountDto account) throws BusinessException;

    /**
     * 使用用户名取得账户信息
     *
     * @param userName 用户名
     * @return 账户信息
     */
    @ApiOperation(value = "取得账户信息")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    AccountDto get(@ApiParam("用户名") String userName);

    /**
     * 检查是否存在账户
     *
     * @param name 账户名
     * @return 是否存在
     */
    @ApiOperation(value = "检查是否存在账户")
    @RequestMapping(value = "/checkExists", method = RequestMethod.GET)
    void checkExists(@ApiParam("账户名") String name) throws BusinessException;

    /**
     * 检查是否已存在企业账户电话号码
     * 同一个电话号码只能绑定一个账户
     *
     * @param phoneNum 电话号码
     * @return 是否存在
     */
    @ApiOperation(value = "检查是否已存在账户电话号码", notes = "同一个电话号码只能绑定一个账户")
    @RequestMapping(value = "/checkExistsPhoneNum", method = RequestMethod.GET)
    void checkExistsPhoneNum(@ApiParam("电话号码") String phoneNum) throws BusinessException;

    /**
     * 冻结账户，将账户置为不可用
     *
     * @param userName 账户名
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "冻结账户", notes = "被冻结的账号登录设备管理系统后，无法打开任何页面")
    @RequestMapping(value = "/freeze", method = RequestMethod.POST)
    void freeze(@ApiParam("账户名") String userName) throws BusinessException;

    /**
     * 解冻账户
     *
     * @param userName 账户名
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "解冻账户")
    @RequestMapping(value = "/unfreeze", method = RequestMethod.POST)
    void unfreeze(@ApiParam("账户名") String userName) throws BusinessException;

    /**
     * 修改账户密码
     *
     * @param changePwd 修改密码信息
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "修改账户密码")
    @RequestMapping(value = "/changePwd", method = RequestMethod.POST)
    void changePwd(@RequestBody ChangePwd changePwd) throws BusinessException;

    /**
     * 取消账户隶属组
     *
     * @param userName 账号
     * @param groupId  账户组
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "取消账户隶属组", notes = "取消组后该账户就不能以该账户组的权限进行登录")
    @RequestMapping(value = "/cancelGroup", method = RequestMethod.POST)
    void cancelGroup(@ApiParam("账号") String userName, @ApiParam("账户组") Integer groupId) throws BusinessException;

    /**
     * 用户登录
     * 此处的登录只是标记用户当前是以哪个账户组登录的，真正的登录是走获取token接口，如果该账户有多种角色需要指定以哪种角色登录
     *
     * @param userName 账号
     * @param groupId  账户组
     * @param role     角色
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "用户登录", notes = "此处的登录只是标记用户当前是以哪个账户组登录的，真正的登录是走获取token接口，如果该账户有多种角色需要指定以哪种角色登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    LoginUserInfo login(@ApiParam("账号") String userName, @ApiParam("账户组") Integer groupId, @ApiParam("角色") String role) throws BusinessException;

    /**
     * 取已登录了的用户信息
     *
     * @param userName 账号
     * @return 用户信息
     */
    @ApiOperation(value = "取已登录了的用户信息")
    @RequestMapping(value = "/getLoginUserInfo", method = RequestMethod.GET)
    LoginUserInfo getLoginUserInfo(@ApiParam("账号") String userName);

    /**
     * 获取账户所在账户组列表
     *
     * @param userName 账号
     * @return 账户组列表
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "获取账户所在账户组列表")
    @RequestMapping(value = "/getAccountGroups", method = RequestMethod.GET)
    List<AccountGroupDto> getAccountGroups(@ApiParam("账号") String userName) throws BusinessException;

    /**
     * 重置密码
     * 重置后会向该账户的手机发送一个随机密码
     *
     * @param userName 账号
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "重置密码", notes = "重置后会向该账户的手机发送一个随机密码")
    @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
    void resetPwd(String userName) throws BusinessException;

    /**
     * 发送找回密码短信，有效期1分钟
     *
     * @param mobile 手机号
     * @return 验证码id
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "发送找回密码短信", notes = "发送找回密码短信，有效期1分钟")
    @RequestMapping(value = "/sendFindPwdMessage", method = RequestMethod.POST)
    String sendFindPwdMessage(String mobile) throws BusinessException;

    /**
     * 先调用发送找回密码短信，再填写验证码提交找回密码
     *
     * @param findPwdDto 找回密码信息
     * @throws BusinessException 业务异常
     */
    @ApiOperation(value = "找回密码", notes = "先调用发送找回密码短信，再填写验证码提交找回密码")
    @RequestMapping(value = "/findPwd", method = RequestMethod.POST)
    void findPwd(@RequestBody FindPwdDto findPwdDto) throws BusinessException;
}
